package com.p2p.cms.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.p2p.base.dao.BaseMapper;
import com.p2p.base.page.PageVo;

/**
 * 
 * 
 * @author fansunion@qq.com 2014年11月3日
 */
public interface PostDao extends BaseMapper {

	String TABLE_NAME = "p2p_post";
	String STATUS_REMOVED = "1";
	String STATUS_NORMAL = "0";

	/***************** 查询 ******************/
	@Select("select * from " + TABLE_NAME + " where id = #{id}")
	Map<String, Object> get(Integer id);

	//@Select("")
	List<Map<String, Object>> listRecent(
			@Param("categoryId") Integer categoryId,
			@Param("count") Integer count);
	
	@Select("select id,category_id,title  from " + TABLE_NAME + " where category_id=#{categoryId} and status=0 order by sort desc limit 0,#{count} ")
	List<Map<String, Object>> listTitleByCategoryId(
			@Param("categoryId") Integer categoryId,
			@Param("count") Integer count);

	@Select("select id,title,summary,create_time  from " + TABLE_NAME + " where status=0 order by id desc  ")
	List<Map<String, Object>> listPage(PageVo page);
	
	@Select("select id,title,summary,create_time  from " + TABLE_NAME + " where status=0 or status =2 order by id desc  ")
	List<Map<String, Object>> listPageAdmin(PageVo page);

	/***************** 修改 ******************/
	@Update("update " + TABLE_NAME + " set update_time = now(), "
			+ " status = " + STATUS_REMOVED + " where id=#{id}")
	void remove(Integer id);

	void add(Map<String, Object> post);

	void update(Map<String, Object> post);

}
